<template>
    <div class="main-box">  
        <div class="main">
            <p class="p-title">
                {{ title }}&nbsp;
            </p>
            <button class="add-btn" @click="operateUser('add')">新增用户</button>
            <div class="table">
                <div class="table-head-box">
                    <div class="table-head">
                        <span class="table-head-item" v-for="(t,i) in Object.values(userFormOption)" :key="i">{{ t }}</span>
                        <span class=" emit" >编辑</span>
                    </div>
                </div>
                <div class="table-body-box">
                    <div class="table-body"  
                    v-for="(item,index) in userFormList" 
                    :key="item.userName">
                        <span class="table-body-item" v-for="(t,i) in Object.keys(item)" :key="i">{{ item[t] }}</span>
                        <div class="operate">
                            <span class="btn remove" @click="operateUser('remove',index)">删除</span>
                            <span class="btn emit" @click="operateUser('emit',index)">编辑</span>
                            <span class="btn resetting" @click="operateUser('resetting',index)">重置</span>

                        </div>
                    </div>
                </div>
            </div>
            <transition enter-active-class="animate__animated animate__fadeIn animate__faster"
        leave-active-class="animate__animated animate__fadeOut animate__faster">
                <div class="modal-box" v-show="PopUpShowInfo.show" @click="closeModelPupUp" >
                    <div class="internal-limit">
                        <p class="p-title">{{ PopUpShowInfo.type === 'add' ? '新增用户' : PopUpShowInfo.type === 'emit' ? '编辑用户' :'' }}</p>
                        <div class="add">
                            <div class="add-input">
                                <label for="name">
                                    <span>用户名：</span>
                                    <input type="text" id="name" v-model="PopUpShowInfo.obj.userName">
                                </label>
                            </div>
                            <div class="add-input">
                                <label for="password">
                                    <span>密码：</span>
                                    <input type="password" id="password" v-model="PopUpShowInfo.obj.password">
                                </label>
                            </div>
                            <div class="add-input">
                                <label for="orderType">
                                    <span>用户类型：</span>
                                    <select name="select " id="orderType" v-model="PopUpShowInfo.obj.userType">
                                        <option :value="item.value" v-for="(item,index) in userTypeOption" :key="index">{{ item.label }}</option>
                                    </select>
                                </label>
                            </div>
                        </div>
                        <div class="add-form">
                            <button class="add-form-btn" @click="submitFrom(PopUpShowInfo.type)">{{ PopUpShowInfo.type === 'add' ? '新增用户' : PopUpShowInfo.type === 'emit' ? '编辑用户' :'' }}</button>

                        </div>

                    </div>
                </div>
            </transition>
        </div>
    </div>
</template>

<script>
import { userFormOption,userTypeOption } from '@/utils/CommonObject';
export default {
    data() {
        return {
            title: '',
            userFormList: [
                {
                    userName:'雷',
                    password:'@Ww1223137536',
                    userType:1,
                },                {
                    userName:'乐',
                    password:'@Ww1223137536',
                    userType:0,
                },                {
                    userName:'梵',
                    password:'@Ww1223137536',
                    userType:2,
                },
            ],
            userTypeOption:userTypeOption,
            userFormOption: userFormOption,
            PopUpShowInfo: {
                show: false,
                type: '',
                index:'',
                obj: {
                    
                }
            },
        }
    },
    methods: {
        operateUser(type, index) {
            this.PopUpShowInfo.type = type;
            this.PopUpShowInfo.index = index;
            if (this.PopUpShowInfo.type === 'remove') {
                this.userFormList.splice(index,1)
            } else if (this.PopUpShowInfo.type === 'emit') {
                this.PopUpShowInfo.show = true
                this.PopUpShowInfo.obj = this.userFormList[index]
            } else if (this.PopUpShowInfo.type === 'add') {
                this.PopUpShowInfo.show = true

            } else if (this.PopUpShowInfo.type === 'resetting') {
                this.userFormList[index] = {
                    serName:'',
                    assword:'',
                    serType:'',
                }
                this.$bus.$emit('openUpPop', {show:false,successShow:true,content:'重置成功'});

            }
        },
        submitFrom(type) {
            if (type === 'add') {
                this.userFormList.push(this.PopUpShowInfo.obj)
                this.PopUpShowInfo.show = false
                this.$bus.$emit('openUpPop', {show:false,successShow:true,content:'添加成功'});
            } else if (type === 'emit') {
                this.userFormList[this.PopUpShowInfo.index] = this.PopUpShowInfo.obj
                this.PopUpShowInfo.show = false
                this.$bus.$emit('openUpPop', {show:false,successShow:true,content:'编辑成功'});
                
            }
        },
        closeModelPupUp() {
            if (event.target.className === 'modal-box') {
                this.PopUpShowInfo.show = false;
            }
            
        }
        
    },
    mounted() { 
    },
}
</script>

<style lang="less" scoped>
.main-box{
    background-color: #ffffff;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    .main{
        background-color: #eaeaea;
        width: 100%;
        min-height: 15rem;
        border-radius: 10px;

        .p-title{
            font-size: 1.5rem;
            font-family: 400;
            padding: 15px 0 ;
            border-bottom: 1px solid #adadad;
        }
        .add-btn{
            border: none;
            border-radius: 5px;
            padding: 5px 15px;
            color: white;
            margin: 15px 0 40px 0;
            background-color: #7136f1;
        }
        .table{
            margin-top: 10px;
            border-radius: 5px;
            border: 1px solid #adadad;

            .table-head-box{
                border: none;
                background: #FFFFFF;
                .table-head{
                    display: flex;
                    justify-content:space-around;
                    border-bottom: 1px solid #adadad;
                    padding: 10px 10px;
                    align-items: baseline;
                    .table-head-item{
                        flex: 1;
                        text-align: center  ;

                    }
                    .emit{
                        flex: 1;

                        color: rgb(0, 0, 0);
                        text-align: center  ;
                        width: 80px!important;
                    }
                }
            }
            .table-body-box{
                background: #FFFFFF;
                .table-body{
                    display: flex;
                    justify-content:space-around;
                    padding: 10px 10px;
                    border-bottom: 1px solid #adadad;
                    align-items: baseline;
                    &:last-child{
                        border:none
                    }
                    .table-body-item{
                        flex: 1;
                        text-align: center  ;
                    }
                    .operate{
                        flex: 1;
                        display: flex;
                        justify-content: center;

                        .btn{
                            color: white;
                            text-align: center  ;
                            border-radius: 8px;
                            padding: 5px 0;
                            width: 60px!important;
                            margin: 0 10px;
                        }
                        .remove{
                            background: #f3406a;
                        }
                        .emit{
                            background: #e1e4eb;
                        }
                        .resetting{
                            background: #12a1ec;
                        }
                    }
                }
            }
        }
    }
}
.modal-box{
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    .add-form{
        width: 100%;
        position: relative;
        .add-form-btn{
            border: none;
            border-radius: 5px;
            padding: 5px 15px;
            color: white;
            background-color: #12a1ec;
            position: absolute;
            right: 10px;
            bottom: 10px;
        }
    }
    .internal-limit{
        background-color: white;
        border-radius: 7px;
        min-width: 40rem;
        min-height: 20rem;
        position: relative;
        .add{
            padding: 30px;
                .number{
                    font-size: 1.6rem;
                    margin-bottom: 14px;

                }
                .add-input{

                    margin-bottom: 14px;
                    label{
                        display: flex;
                        flex-direction: column;
                    }
                    span{
                        font-size: 1.1rem;
                        font-family: 400;
                        margin-bottom: 4px;
                    }
                    &:last-of-type {
                        margin-bottom: 100px;
                    }
                }
                input,select{
                    border: 1px solid #adadad;
                    border-radius: 5px;
                    height: 35px;
                    padding: 0 0 0 10px ;
                }
                .processParameter{
                    margin-bottom: 14px;
                    display: flex;
                    flex-direction: column;
                    p{
                        margin-bottom: 15px;
                    }
                }
                .formbox{
                    display: flex;
                    justify-content: space-between;
                    .item{
                        display: flex;
                        align-items: center;
                        margin-bottom: 15px;
                        span:nth-child(1){
                            display: inline-block;
                            width: 80px;

                        }
                        p{
                            width: 300px;
                            display: flex;
                            align-items: center;

                            input{
                                flex: 1;
                            }
                            span{
                                margin: 0 5px;
                            }
                        }
                    }
                    .formbox-left{
                        width: 45%;
                    }
                    .formbox-right{
                        width: 45%;

                    }
                }
        }
    }
}
</style>